import os, sys
PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, PROJECT_PATH)


import traceback
from functions import *

FUNCTIONS_MAP = {
    "create" : create_fun,
    "add" : add_fun,
    "drop" : drop_fun,
    "del" : del_fun,
    "set_model" : set_model_fun,
    "update" : update_fun,
    "get" : get_fun,
    "list" : list_fun,
    "path" : path_fun,
    "help" : help_fun,
    "cls" : cls_fun,
}

def switch_order(conn, order, arg_list):
    fun = FUNCTIONS_MAP.get(order)
    if fun is None :
        return "unknown order"
    return fun(conn, arg_list)



def main():
    global LEVEL
    conn = getConnecion()
    create_fun(conn, [])
    console_print("输入 help 获取帮助")
    console_print('******************************************')
    while True:
        try:
            order, arg_list = parse_input(input(">> "))
            if order == []:
                continue
            order = order[0]
            if order == "e":
                break
            console_print(switch_order(conn, order, arg_list))
        except Exception as e:
            error_info = traceback.format_exc() if get_level() == "debug" else e.args
            console_print(error_info)
            
    conn.close()

main()